<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ include file="../common/tags.jsp" %>  
<%
	String path = request.getContextPath();
%>
<c:set var="reg_obj_str" value="${(searchType==null || searchType=='')?'customerlist':'customerlist1'}"/>
<script>
	function submitSelectForm(form){
		if('${searchType}'=='')
			return navTabSearch(form);
		else
	    	return dwzSearch(form, 'dialog');
	}
	function favourableEntityBringBack(customerId , cardName){
	$.bringBack({customerId:customerId , cardName:cardName});
	}

	function cardEntityBringBack(customerId,merchantNamer,merchantCode,pre){
		//查询该商户下的级别
		var leveUrl = "<%=path%>/ajax/ajaxGetLevelByCustomer.do?customerId="+customerId;
		var agioUrl = "<%=path%>/ajax/ajaxGetAgioByCustomer.do?customerId="+customerId;
		var add_card_agio_selectObj = parent.document.getElementById(pre+"_cardEntity_cardAgio");
		var add_card_level_selectObj = parent.document.getElementById(pre+"_cardEntity_cardLever");
		getCardLevel(leveUrl,customerId,add_card_level_selectObj,null);
		getCardAgio(agioUrl,customerId,add_card_agio_selectObj,null);
		$.bringBack({customerId:customerId, merchantNamer:merchantNamer,merchantCode:merchantCode})
	}
	
	function cardLevelBringBack(customerId,customerName){
		parent.changeCustomer(customerId);
		$.bringBack({customerId:customerId, customerName:customerName});
	}
	
	function cardAgioBringBack(customerId,customerName){
		$.bringBack({customerId:customerId, customerName:customerName});
	}
	
	function productBringBack(customerId,customerName,pre){
		//查询该商户下的商品分类
		var productUrl = "<%=path%>/ajax/ajaxGetProductKindByCustomer.do?customerId="+customerId;
		var add_product_kind_selectObj = parent.document.getElementById(pre+"_productKind");
		getProductKind(productUrl,add_product_kind_selectObj,null);
		$.bringBack({customerId:customerId, customerName:customerName})
	}
	function getCardEntityAndBringBack(customerId,customerName) {
		parent.getCardEntityByCustomer(customerId);
		$.bringBack({linkId:customerId, customerName:customerName});
	}
	function rechargeCustomer(){
			var checkValue = "";
			$('input[type="checkbox"][name="ids"]:checked').each(
				function(){ 
		     		checkValue += $(this).val() + ","; 
				}
            );
			if(checkValue == ""){
				alertMsg.error('请选择商家');
				return;
			}else{
				var url = "<%=path %>/memberCard/rechargeCard.action?ids="+checkValue+"&type=CUSTOMER";;
				var options = {mask:true,mixable:true,minable:true,resizable:true}; 
				$.pdialog.open(url, "rechargeCusomerDialog", "充值",options);
			}
		}
function cardEntityListBringBack(customerId,customerName,customerCode){
	if (parent.initCardLevel){
		initCardLevel(customerId);
	}
	$.bringBack({customerId:customerId, customerName:customerName,customerCode:customerCode});
}
</script>
<script type="text/javascript" src="<%=path%>/projectjs/regioninfo.js" ></script>
<script type="text/javascript" src="<%=path%>/projectjs/cardEntity.js" ></script>
<script type="text/javascript" src="<%=path%>/projectjs/productKind.js" ></script>
<form id="pagerForm" method="post" action="<%=path %>/customer/listCustomer.action">
	<input type="hidden" name="pageRequest" value="1" />
	<input type="hidden" name="pageNum" value="${paginator.pageIndex}" />
	<input type="hidden" name="numPerPage" value="${paginator.pageSize}" />
</form>

<div class="pageHeader">
	<form onsubmit="return submitSelectForm(this);" rel="pagerForm" action="<%=path %>/customer/listCustomer.action" method="post">
	<input type="hidden" name="searchType" value="${searchType}"/>
	<input type="hidden" name="templateId" value="${templateId}"/>
	<input type="hidden" name="lookUpPre" value="${lookUpPre}"/>
	<div class="searchBar">
		<ul class="searchContent">
			<li>
				<label style="text-align: right;">所属省份：</label>
				<input type="hidden" id="${reg_obj_str}_db_province_id" value="<s:property value="customerVO.provinceRegionId" />"/>
				<select name="customerVO.provinceRegionId" id="${reg_obj_str}_province_id" onchange="getAllCity('${reg_obj_str}')" class="required">
					<option value="">请选择</option>
				</select>
			</li>
			<li>
				<label style="text-align: right;">所属市级：</label>
				<input type="hidden" id="${reg_obj_str}_db_city_id" value="<s:property value="customerVO.cityRegionId" />"/>
				<select name="customerVO.cityRegionId" id="${reg_obj_str}_city_id" onchange="getAllDistrict('${reg_obj_str}')" class="required">
					<option value="">请选择</option>
				</select>
			</li>
			<li>
				<label style="text-align: right;">所属城区：</label>
				<input type="hidden" id="${reg_obj_str}_db_district_id" value="<s:property value="customerVO.districtRegionId" />"/>
				<select name="customerVO.districtRegionId" id="${reg_obj_str}_district_id" class="required">
					<option value="">请选择</option>
				</select>
			</li>
		</ul>
		<ul class="searchContent">
			<li>
				<label style="text-align: right;">商家编码：</label>
				<input type="text" name="customerVO.code" value='<s:property value="customerVO.code" />' size="20"/>
			</li>
			<li>
				<label style="text-align: right;">商家名称：</label>
				<input type="text" name="customerVO.name" value='<s:property value="customerVO.name" />' size="20"/>
			</li>
			<li>
				<label style="text-align: right;">合同编号：</label>
				<input type="text" name="customerVO.contractCode" value='<s:property value="customerVO.contractCode" />' size="20"/>
			</li>
		</ul>
		<ul class="searchContent">
			<li>
				<label style="text-align: right;">联盟优惠：</label>
				<s:select name="customerVO.haveAllianceFavourable" list="%{#{'':'全部',1:'是',0:'否'}}" listKey="key" listValue="value" cssClass="combox"></s:select>
			</li>
			<li>
				<label style="text-align: right;">核心商家：</label>
				<s:select name="customerVO.isCoreCustomer" list="%{#{'':'全部',1:'是',0:'否'}}" listKey="key" listValue="value" cssClass="combox"></s:select>
			</li>
			<li>
				<label style="text-align: right;">分类：</label>
				<select name="customerVO.customerKindId" class="combox">
					<option value="">请选择</option>
					<s:iterator value="customerKindList" id="customerKind" status="st">
						<option value="<s:property value="id" />"${customerVO.customerKindId==customerKind.id?" selected":""}><s:property value="name" /></option>
					</s:iterator>
				</select>
			</li>
		</ul>
		<ul class="searchContent">
			<li>
				<label style="text-align: right;">加盟日期：</label>
				从<input type="text" name="customerVO.joinBegtime" class="date" readonly="false" value='<s:date name='customerVO.joinBegtime' format="yyyy-MM-dd"/>' size="10"/>
				到<input type="text" name="customerVO.joinEndtime" class="date" readonly="false" value='<s:date name='customerVO.joinEndtime' format="yyyy-MM-dd"/>' size="10"/>
			</li>
			<li>
				<label style="text-align: right;">总发卡量：</label>
				从<input type="text" name="customerVO.gtcardTotal" value='<s:property value="customerVO.gtcardTotal" />' class="number" size="8"/>
				到<input type="text" name="customerVO.ltcardTotal" value='<s:property value="customerVO.ltcardTotal" />' class="number"  size="8"/>
			</li>
			<li>
				<label style="text-align: right;">余额查询：</label>
				从<input type="text" name="customerVO.gtmoney" value='<s:property value="customerVO.gtmoney" />' size="8"/>
				到<input type="text" name="customerVO.ltmoney" value='<s:property value="customerVO.ltmoney" />' size="8"/>
			</li>
		</ul>
		<div class="subBar">
			<ul>
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit">查询</button></div></div></li>
				<c:if test="${searchType=='msgTemplate'}">
					<li><div class="button"><div class="buttonContent"><button type="button" multLookup="ids" warn="请选择商家">选择带回</button></div></div></li>
				</c:if>
			</ul>
		</div>
	</div>
	</form>
</div>
<div class="pageContent">
	<c:if test="${searchType==null || searchType==''}">
	<div class="panelBar">
		<ul class="toolBar">
			<shiro:hasPermission name="addCustomer">
			<li><a class="add" href="<%=path %>/customer/addCustomer.action" target="navTab"><span>添加商家</span></a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="editCustomer">
			<li><a class="edit" href="<%=path %>/customer/editCustomer.action?customerVO.id={sid_user}" target="navTab" warn="请选择一条记录"><span>修改</span></a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="deleteCustomer">
			<li><a title="确实要删除吗?" target="selectedTodo" rel="ids" postType="string" href="<%=path %>/customer/deleteCustomer.action?status=1" class="delete"><span>删除</span></a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="rechargeCard">
			<li><a rel="ids" href="javascript:rechargeCustomer();" mask=true postType="string" warn="请选择记录" class="edit"><span>充值</span></a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="relieveCustomer">
			<li><a title="确实要解除合作吗?" target="selectedTodo" rel="ids" postType="string" href="<%=path %>/customer/relieveCustomer.action?status=0" class="delete"><span>解除合作</span></a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="regainCustomer">
			<li><a title="确实要恢复合作吗?" target="selectedTodo" rel="ids" postType="string" href="<%=path %>/customer/regainCustomer.action?status=1" class="add"><span>恢复合作</span></a></li>
			</shiro:hasPermission>
		</ul>
	</div>
	</c:if>
	<table class="table" width="1400" layoutH="214">
		<thead>
			<tr>
	        <c:if test="${searchType==null || searchType=='' || searchType=='msgTemplate'}">
	             <th width="30"><input type="checkbox" group="ids" class="checkboxCtrl"></th>
			</c:if>
				<th>商家编码</th>
				<th>商家名称</th>
				<th width="80">商家图片</th>
				<c:if test="${SESSION_USER.customer==null}">
				<th width="50">排序值</th>
				<th width="50">置顶</th>
				</c:if>
				<th width="80">合同编码</th>
				<th  width="90">加盟开始日期</th>
				<th width="90">加盟结束日期</th>
				<th width="80">联系人</th>
				<th  width="80">帐户余额</th>
				<th>固定电话</th>
				<th>移动电话</th>
				<th>总发卡量</th>
				<th>是否有优惠券</th>
				<th>是否支持联盟优惠</th>
				<th  width="80">合作状态</th>
				<c:if test="${searchType==null||searchType==''}">
					<th width="90">操作</th>
				</c:if>
				<c:if test="${searchType!=null&&searchType!=''&&searchType!='msgTemplate'}">
					<th>查找带回</th>
				</c:if>
			</tr>
		</thead>
		<tbody>
			<s:iterator value="customerList" id="customer" status="st">
				<tr target="sid_user" rel="<s:property value="id" />">
				<c:choose>
	             	<c:when test="${searchType=='msgTemplate'}">
	             		<td>
	             			<input name="ids" ${fn:contains(customers,customer.id) ? 'checked=checked' : ''} value="{customerIds:'${customer.id}', customerNames:'${customer.name}',customerCode:'${customer.code}'}" type="checkbox">
						</td>
					</c:when>
					<c:when test="${searchType==null||searchType==''}">
  						 <td>
							<input name="ids" value="<s:property value="id" />" type="checkbox">
						</td>
					</c:when>
				</c:choose>  
             <td><s:property value="code" /></td>	
             <td><s:property value="name" /></td>
             <td><c:if test="${picName!=null&&picName!=''}"><a href="<%=path%>/jsp/common/preview_image.jsp?folder=customer&picNames=${picName}&id=${id}" target="dialog" rel="customerList" max="true" title="商家图片" width="800" height="480">查看图片</a></c:if></td>
             <c:if test="${SESSION_USER.customer==null}">
             <td>${customer.top}</td>
             <td><a title="您确定要置顶该商家吗？置顶将优先显示！" target="ajaxTodo" href="<%=path%>/customer/updateTopCustomer.action?customerVO.id=${customer.id}">置顶</a></td>
             </c:if>
             <td><s:property value="contractCode" /></td>	
	<td><s:date name="joinBegtime" format="yyyy-MM-dd" /></td>
	<td><s:date name="joinEndtime" format="yyyy-MM-dd" /></td>
             <td><s:property value="linkman" /></td>	
             <td>${money == null ? 0 : money}</td>	
             <td><s:property value="telphone" /></td>	
             <td><s:property value="mobile" /></td>	
             <td><s:property value="cardTotal" /></td>
             <td>
               <s:if test="%{#customer.haveFavourable == 1}">是</s:if>
                 <s:else>否</s:else>
             </td>
             <td>
             	<s:if test="%{#customer.haveAllianceFavourable == 1}">是</s:if>
                 <s:else>否</s:else>
             </td>
             <td>
               <s:if test="%{#customer.cooperationStaus == 0}">已解除</s:if>
                 <s:else>正常</s:else>
             </td>
            	 	<c:if test="${searchType==null||searchType==''}">
					<td>
						<shiro:hasPermission name="editCustomer">
						<a title="编辑" target="navTab" href="<%=path %>/customer/editCustomer.action?customerVO.id=<s:property value="id" />" class="btnEdit">编辑</a>
						</shiro:hasPermission>
						<shiro:hasPermission name="deleteCustomer">
						<a title="确实要删除这条记录吗?" target="ajaxTodo" href="<%=path %>/customer/relieveCustomer.action?ids=<s:property value="id" />" class="btnDel">删除</a>
						</shiro:hasPermission>
						<a title="查看" target="navTab" href="<%=path%>/customer/viewCustomer.action?customerVO.id=${id}" class="btnView">查看</a>
					</td>
					</c:if>
					<c:if test="${searchType == 'favourableEntity'}">
					<td><a class="btnSelect" href="javascript:$.bringBack({customerId:'${customer.id}', customerName:'${customer.name}'})" title="查找带回">选择</a>
					</td>
					</c:if>
					<c:if test="${searchType == 'cardEntity'}">
					<td><a class="btnSelect" href="javascript:cardEntityBringBack('${customer.id}','${customer.name}','${customer.code}','${lookUpPre}');" title="查找带回">选择</a>
					</td>
					</c:if>
					<c:if test="${searchType == 'active'}">
					<td><a class="btnSelect" href="javascript:$.bringBack({customerId:'${customer.id}', customerName:'${customer.name}'})" title="查找带回">选择</a>
					</td>
					</c:if>
					<c:if test="${searchType == 'cardLevel'}">
					<td><a class="btnSelect" href="javascript:cardLevelBringBack('${customer.id}', '${customer.name}');" title="查找带回">选择</a>
					</td>
					</c:if>
					<c:if test="${searchType == 'cardAgio'}">
					<td><a class="btnSelect" href="javascript:cardAgioBringBack('${customer.id}', '${customer.name}');" title="查找带回">选择</a>
					</td>
					</c:if>
					<c:if test="${searchType == 'advertising'}">
					<td><a class="btnSelect" href="javascript:getCardEntityAndBringBack('${customer.id}','${customer.name}');" title="查找带回">选择</a>
					</td>
					</c:if>
					<c:if test="${searchType == 'product'}">
					<td><a class="btnSelect" href="javascript:productBringBack('${customer.id}','${customer.name}','${lookUpPre}');" title="查找带回">选择</a>
					</td>
					</c:if>
				</tr>
			</s:iterator>
		</tbody>
	</table>
	<div class="panelBar">
		<div class="pages">
				<span>显示</span>
				<select class="combox" name="numPerPage" onchange='<s:if test="%{searchType==null||searchType==''}">navTabPageBreak({numPerPage:this.value})</s:if><s:else>dialogPageBreak({numPerPage:this.value})</s:else>'>
					<option value="15" <c:if test="${paginator.pageSize==15}">selected='selected'</c:if> >15</option>
					<option value="30" <c:if test="${paginator.pageSize==30}">selected='selected'</c:if> >30</option>
					<option value="50" <c:if test="${paginator.pageSize==50}">selected='selected'</c:if> >50</option>
					<option value="100" <c:if test="${paginator.pageSize==100}">selected='selected'</c:if> >100</option>
					<option value="200" <c:if test="${paginator.pageSize==200}">selected='selected'</c:if> >200</option>
				</select>
				<span>条，共${paginator.totalCount}条</span>
			</div>
			<div class="pagination" targetType="${(searchType==null||searchType=='')?'navTab':'dialog'}" totalCount="${paginator.totalCount}" 
				numPerPage="${paginator.pageSize}" pageNumShown="10" currentPage="${paginator.pageIndex}"></div>

	</div>
</div>
<script type="text/javascript">
	var ${reg_obj_str}=new RegionInfo("${pageContext.request.contextPath}","${reg_obj_str}_province_id","${reg_obj_str}_db_province_id","${reg_obj_str}_city_id","${reg_obj_str}_db_city_id","${reg_obj_str}_district_id","${reg_obj_str}_db_district_id","${reg_obj_str}");
</script>